class InvalidAgeException extends Exception {
    public InvalidAgeException(String message) {
        super(message);
    }
}//年龄无效异常

class InvalidNameException extends RuntimeException {
    public InvalidNameException(String message) {
        super(message);
    }
}//姓名无效异常

class UserReg{
    public void validateAge(int age) throws InvalidAgeException {
        if (age < 18) {
            throw new InvalidAgeException("年龄小于18岁，不符合注册要求");
        }
    }//验证年龄

    public void validateName(String name) {
        if (name == null || name.length() < 3) {
            throw new InvalidNameException("姓名为空或长度小于3，不符合注册要求");
        }
    }//验证姓名

    public void registerUser(String name, int age) {
        try {
            validateName(name);
            validateAge(age);
            System.out.println("注册成功");
        } catch (InvalidAgeException e) {
            System.out.println("年龄验证失败: " + e.getMessage());
        } catch (InvalidNameException e) {
            System.out.println("姓名验证失败: " + e.getMessage());
        }
    }
}

class RegistrationService {
    public void startRegistration(String name, int age) {
        UserReg userRegistration = new UserReg();
        userRegistration.registerUser(name, age);
    }
}

public class Homework_6_exception{
    public static void main(String[] args) {
        // 正常注册测试
        RegistrationService registrationService = new RegistrationService();
        registrationService.startRegistration("Dicaprio", 20);

        // 姓名无效测试
        registrationService.startRegistration("",20);

        // 年龄无效测试
        registrationService.startRegistration("Dicaprio", 15);
    }
}